// pages/TradingArea/videoPlay.js
const app = getApp()


Page({

  data: {
    navHeight: '',
    isFromMyCenterVideo: false,

    img: '',
    name: '',
    src: '',
    desc: '',
    type: '',
    couponBagId: '',
    shopGroupId: '',
    invitationAccountId: ''
  },



  onLoad(options) {
    this.getNavHeight()

    const {
      img,
      name,
      video,
      videoDesc,
      type,
      couponBagId,
      isFromMyCenterVideo
    } = JSON.parse(options.data)

    this.setData({
      isFromMyCenterVideo,
      img,
      name,
      src: video,
      desc: videoDesc,
      type,
      couponBagId,
    })
    // 创建video上下文
    this.video = wx.createVideoContext('video', this)
    console.log(this.data.navHeight);

  },
  // 获取导航栏加状态栏高度（导航栏底部坐标）
  getNavHeight() {
    let query = wx.createSelectorQuery();
    query.select('.navBar').boundingClientRect();
    query.exec((res) => {
      this.setData({
        navHeight: res[0].bottom
      })
    });
  },

  videoPlay() {
    if(!this.data.isFromMyCenterVideo){
      wx.navigateBack()
    }else{
      let isAutoplay = this.data.isAutoplay
      isAutoplay = !isAutoplay
  
      isAutoplay ? this.video.pause() : this.video.play()
  
      this.setData({
        isAutoplay
      })
    }
   
  },

  toDetail() {
    const isFromMyCenterVideo = this.data.isFromMyCenterVideo
    const type = this.data.type
    const id = this.data.couponBagId

    if (isFromMyCenterVideo) { // 来自我的中心
      wx.navigateTo({
        url: '/pages/TradingArea/GiftBagDetail?id=' + id + "&type=" + type + "&isFromMyCenterVideo=" + true,
      })
    } else {
      wx.navigateBack()
    }

  }

})